package cn.stylefeng.guns.modular.tool.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.tool.entity.ToolOrderPutDetailed;
import cn.stylefeng.guns.modular.tool.mapper.ToolOrderPutDetailedMapper;
import cn.stylefeng.guns.modular.tool.model.params.ToolOrderPutDetailedParam;
import cn.stylefeng.guns.modular.tool.model.result.ToolOrderPutDetailedResult;
import  cn.stylefeng.guns.modular.tool.service.ToolOrderPutDetailedService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 云仓入库明细表 服务实现类
 * </p>
 *
 * @author zhucx
 * @since 2023-04-03
 */
@Service
public class ToolOrderPutDetailedServiceImpl extends ServiceImpl<ToolOrderPutDetailedMapper, ToolOrderPutDetailed> implements ToolOrderPutDetailedService {

    @Override
    public void add(ToolOrderPutDetailedParam param){
        ToolOrderPutDetailed entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(ToolOrderPutDetailedParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(ToolOrderPutDetailedParam param){
        ToolOrderPutDetailed oldEntity = getOldEntity(param);
        ToolOrderPutDetailed newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public ToolOrderPutDetailedResult findBySpec(ToolOrderPutDetailedParam param){
        return null;
    }

    @Override
    public List<ToolOrderPutDetailedResult> findListBySpec(ToolOrderPutDetailedParam param){
        return this.baseMapper.findListBySpec(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(ToolOrderPutDetailedParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(ToolOrderPutDetailedParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private ToolOrderPutDetailed getOldEntity(ToolOrderPutDetailedParam param) {
        return this.getById(getKey(param));
    }

    private ToolOrderPutDetailed getEntity(ToolOrderPutDetailedParam param) {
        ToolOrderPutDetailed entity = new ToolOrderPutDetailed();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public boolean saveBatchList(List<ToolOrderPutDetailedParam> list) {
		return this.baseMapper.saveBatchList(list);
	}

	@Override
	public List<ToolOrderPutDetailedResult> totalListByGgoodsSpec(ToolOrderPutDetailedParam param) {
		return this.baseMapper.totalListByGgoodsSpec(param);
	}

}
